const gulp=require('gulp')
const html=require('gulp-htmlmin')
const css=require('gulp-cssmin')
const autoprefixer=require('gulp-autoprefixer')
const uglify=require('gulp-uglify')
const babel=require('gulp-babel')
const sass = require('gulp-sass')
// const webserver=require('gulp-webserver')
const del=require('del')

const apiHandler=()=>{
    return gulp.src('./src/api/**')
    .pipe(gulp.dest('./dist/api'))
}

const imagesHandler=()=>{
    return gulp.src('./src/images/**')
    .pipe(gulp.dest('./dist/images'))
}

const image_loginHandler=()=>{
    return gulp.src('./src/image_login/**')
    .pipe(gulp.dest('./dist/image_login'))
}

const phpHandler=()=>{
    return gulp.src('./src/php/**')
    .pipe(gulp.dest('./dist/php'))
}

const fontHandler=()=>{
    return gulp.src('./src/font/**')
    .pipe(gulp.dest('./dist/font'))
}

const htmlHandler = ()=>{
    return gulp.src('./src/pages/**')
    .pipe(html(
        {
        removeAttributeQuotes:true,
        removeComments:true,
        minifyCSS:true,
        minifyJS:true,
        collapseBooleanAttributes:true,
        collapseWhitespace:true
    }
))
    .pipe(gulp.dest("./dist/pages"))
}

const cssHandler=()=>{
    return gulp.src('./src/css/**')
    .pipe(autoprefixer())
    .pipe(css())
    .pipe(gulp.dest('./dist/css'))
}

const scssHandler = ()=>{
    return gulp.src('./src/sass/**')
    .pipe(sass())
    .pipe(autoprefixer())
    .pipe(css())
    .pipe(gulp.dest('./dist/css'))
}

const uglifyHandler=()=>{
    return gulp.src('./src/js/**')
    .pipe(babel({
        presets:['@babel/env']
    }))
    .pipe(uglify())
    .pipe(gulp.dest('./dist/js'))
}

const delHandler=()=>{
    return del(['./dist'])
}
module.exports.default=
gulp.series(
    delHandler,
    gulp.parallel(apiHandler,image_loginHandler,phpHandler,fontHandler,cssHandler,imagesHandler,scssHandler,htmlHandler,uglifyHandler)
)
